<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
		print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';


}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>CMS | Edit Content</title>
</head>
<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
         <link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />



<?
$cmsId = $_GET['cmsid'];
$type	= $_GET['type'];

if(isset($_POST['prev']))

{
	$cmsId = $_GET['cmsid'];
	$type	= $_GET['type'];
	$cmsTitle = $_POST['cmsTitle'];
	$cmsContent2 = $_POST['cmsContent'];
	$datetime = date("F j, Y H:i:s");
	$onerep = 1;
	
	
	
	print '
                    <table width="700" border="0">

                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td class="extra">Title: '.$cmsTitle.'</td><td align="right" class="extra">'.$datetime.'</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><label>
                          '.$cmsContent2.'
                        </label></td>
                      </tr>
                    </table><br /><br />
                        ';
	
	
}
else if(isset($_POST['create']))
{

		$cmstitle = $_POST['cmsTitle'];
		$cmsContent = $_POST['cmsContent'];	
		$createby = $_SESSION['us'];
		$datetime = date("F j, Y H:i:s");
		
		
		if($cmstitle=="" || $cmsContent =="")
		{
		
		print '
		
		<script type="text/javascript">
		
		alert("Please complete the fields.");
		window.location = "editContent.php?cmsid='.$cmsId.'";
		</script>
		
		
		';
		
		
		}
		
		else {
		
	
		$update = mysql_query("UPDATE tblcms SET cmsTitle = '$cmstitle',
														cmsContent = '$cmsContent'
														 WHERE cmsId = '$cmsId' ") or die (mysql_error());
		//n33d p 3dit nung d3sign
		print '
		
		<script type="text/javascript">
		
		alert("Successfully saved changes!");
		 window.history.go(-2);
		
		</script>
		
		
		';
		
		
		
		
		}


}

?>

<?

$topicquery = mysql_query("SELECT * from tblcms WHERE cmsId = '$cmsId' ");
		while($row = mysql_fetch_array($topicquery))
		{
			$cmsId = $row['cmsId'];
			$cmsTitle 	 = $row['cmsTitle'];
			$cmsContent = $row['cmsContent'];
			$date 	 = $row['cmsDate'];
			$createby = $row['cmsEditor'];
			$createid = $row['cmsEditorBy'];
			$type 	  = $row['cmsType'];
			$status = $row['cmsStatus'];
			
			
			if($type == 'home'):
		$typeCat = 'viewHome';
		$typeCategory = 'Home';
		//Filipino Section
		elseif($type == 'about'):
		$typeCat = 'viewAbout';
		$typeCategory = 'About';
		//English Section
		elseif($type == 'annouce'):
		$typeCat = 'viewAnnounce';
		$typeCategory = 'Annoucement';
		//Math Section
		elseif($type == 'gallery'):
		$typeCat = 'viewGallery';
		$typeCategory = 'Gallery';
		//Contact Us Section
		elseif($type == 'contact'):
		$typeCat = 'viewContact';
		$typeCategory = 'Contact';
endif;
		}

?>


<body>

 <div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
     <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
       <!-- <div id="chef_ind"> open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
  </div>
        
   <!--   </div>close left -->
      
      
          <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3_students"><h2>Website Management</h2> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg1"><!--open booking -->
        <div align="center" class="mainbox">
        
     <form id="form2" name="form2" method="post" action="editContent.php?cmsid=<? print $cmsId; ?>">
                    <table width="600" border="0">
                    <tr>
                        <td colspan="6">
                    <a class="siteloc" href="cms.php">CMS</a>   <img width="25" height="15" border="0" src="../images/arrow.png"><a class="siteloc" href="<? print $typeCat; ?>.php"><? print $typeCategory; ?></a>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="#">Edit Content</a>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" background="catbg.png" colspan="5" class="cat"><? print $cmsTitle; ?></td>
                    </tr>
                    <tr>
                  <td height="23" class="label">Edit Content</td>
                	</tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                
				
			
			
                        <td class="extra">Title: <input name="cmsTitle" type="text" id="cmsTitle" size="113" value="<? print $cmsTitle; ?>" /></td>
                	
                     
                    </tr>
                      <tr>
                        <td>&nbsp; </td>
                      </tr>
                      <tr>
                        <td><textarea id="cmsContent" name="cmsContent" rows="15" cols="80" style="width: 70%">
                          <?  if($onerep==1)
						{
						print $cmsContent2;
						}
						else{
						print $cmsContent;}
						
						 ?>
                          </textarea>
                         
   
                          </td>
                      </tr>
                      <tr>
                        <td align="center"><label>
                         <input value='Back' type='button' id='btnb' onclick='history.go(-1); return false;' />  <!--<input type="button" name="Submit" value="toggle editor" onclick="javascript:toggleEditor('elm1');" />--> 
                          <input type="submit" name="create" id="create" value="Submit" />
                        </label></td>
                      </tr>
                    </table>
            </form>    
            </div>   
</div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>



	

